package tcpClient;

import java.util.ArrayList;

public class ConfirmationHolder {

	private static ArrayList<String> confirms;
	private static final Object singletonObject = new Object();
	private static ConfirmationHolder instance;
	
	public ConfirmationHolder() {
		confirms = new ArrayList<String>();
	}

	public static ConfirmationHolder getInstance(){
		if(instance == null){
			synchronized (singletonObject){
				if(instance == null) instance = new ConfirmationHolder();
			}
		}
		return instance;
	}
	
	public void add(String username){
		synchronized (this) {
			confirms.add(username);
		}
	}
	
	public void removeAll(){
		synchronized (this) {
			confirms.removeAll(confirms);
		}
	}
	
	public String getConfirms(){
		String allConfirms = "";
		
		synchronized (this) {
			for (int i = 0; i < confirms.size(); i++) {
				 if(i<confirms.size()-1) allConfirms += confirms.get(i).toString()+"\n";
				 else allConfirms += confirms.get(i).toString();
			}
		}		
		
		return allConfirms;
	}
	
}
